package com.niiwoo.civet.user.enums;

import com.niiwoo.civet.user.constants.LoginAccountErrorCode;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;


/**
 * 用户短信类型枚举
 */
@Getter
@AllArgsConstructor
public enum UserSMSTypeEnum {

    REGISTER((byte) 1, "注册", 120, 5, LoginAccountErrorCode.SMS_SEND_TIMES_OVER_DAY_THRESHOLD, 10, LoginAccountErrorCode.SMS_SEND_TIMES_OVER_MONTH_THRESHOLD),
    LOGIN((byte) 2, "登录", 120, 3, LoginAccountErrorCode.LOGIN_SMS_SEND_TIMES_OVER_DAY_THRESHOLD, 0, null),
    RESET_LOGIN_PASSWORD((byte) 3, "重置登录密码", 120, 3, LoginAccountErrorCode.RESET_LOGIN_PASSWORD_SMS_SEND_TIMES_OVER_DAY_THRESHOLD, 0, null),
    BIND_THIRD_PART_ACCOUNT((byte) 5, "绑定第三方账号", 120, 5, LoginAccountErrorCode.BIND_THIRD_ACCOUNT_SMS_TIMES_OVER, 0, null),
    UNLOCK_ACCOUNT((byte) 6, "解锁账号", 180, 0, null, 0, null),
    OLD_CHANGE_MOBILE_NO((byte) 7, "旧更换手机号", 120, 5, LoginAccountErrorCode.CHANGE_MOBILE_SMS_SEND_TIMES_OVER_DAY_THRESHOLD, 0, null),
    NEW_CHANGE_MOBILE_NO((byte) 8, "新更换手机号", 120, 5, LoginAccountErrorCode.CHANGE_MOBILE_SMS_SEND_TIMES_OVER_DAY_THRESHOLD, 0, null),
    CREDITOR_RIGHTS_TRANSFER((byte) 9, "债权转让", 120, 50, LoginAccountErrorCode.CREDITOR_RIGHTS_TRANSFER_SMS_SEND_TIMES_OVER_DAY_THRESHOLD, 0, null);

    private Byte value;

    private String text;

    private int codeExpireTime;

    private int dayThreshold;

    private String dayThresholdErrorCode;

    private int monthThreshold;

    private String monthThresholdErrorCode;

    public static UserSMSTypeEnum of(Byte value) {
        if (value != null) {
            for (UserSMSTypeEnum s : values()) {
                if (s.value.equals(value)) {
                    return s;
                }
            }
        }
        return null;
    }


    public static boolean except(Byte value, UserSMSTypeEnum... status) {
        return (status != null && status.length > 0) && Arrays.asList(status).contains(of(value));
    }

}
